package com.gxa.day2022_07_14.homework.change_system3;

import java.util.Scanner;

import static com.gxa.day2022_07_14.homework.change_system3.OrderSystem3.dishArray;
import static com.gxa.day2022_07_14.homework.change_system3.OrderSystem3.orderArray;

public class Dish {
    static Scanner scanner = new Scanner(System.in);

    int id;
    String dishName;
    double dishPrice;
    int praiseNum;
    String isKeepPraise;


    public Dish(int id,String dishName,double dishPrice,int praiseNum){
        this.id=id;
        this.dishName= dishName;
        this.dishPrice = dishPrice;
        this.praiseNum = praiseNum;
    }
    public Dish(){

    }


    /**
     * 我要点赞
     */
    static void praise() {
        boolean isPraiseDishFind =false;
        System.out.println("***我要点赞***");
        printDishMenu();
        System.out.print("请选择你要点赞的菜品序号：");
        int praiseId = scanner.nextInt();

        for (int i = 0; i < dishArray.length; i++) {//找到要点赞的值
            if (dishArray[i] != null && praiseId == (i + 1) ) {
                isPraiseDishFind = true;
                //点赞
                dishArray[praiseId - 1].praiseNum++;//点赞数加1
                System.out.println("点赞成功！");
                printDishMenu();
            }
        }
        if (!isPraiseDishFind) {
            System.out.println("点赞失败，该菜品不存在！");
        }
    }

    static void printDishMenu() {
        System.out.println("序号\t 菜品\t 单价\t点赞数");
        for (int i = 0; i < dishArray.length; i++) {
            String price = dishArray[i].dishPrice + "元";
            String praiseNum = (dishArray[i].praiseNum) > 0 ? dishArray[i].praiseNum + "赞" : "";
            System.out.println((i + 1) + "\t" + dishArray[i].dishName + "\t" + price + "\t" + praiseNum);
        }
    }
}
